home *** CD-ROM | disk | FTP | other *** search
/ Day Cry / Day Cry CD.bin / oh_towns / taropyon / splib / splib.lzh / PRG / LHX / GETOPT.C < prev    next >
C/C++ Source or Header  |  1992-12-08  |  2KB  |  78 lines

  1. /***********************************************************
  2.         getopt.c -- get options
  3. ***********************************************************/
  4. #include    "lh386.h"
  5.  
  6. #include    <ctype.h>
  7. #ifndef __HIGHC__
  8. #    include    <stddef.h>
  9. #else
  10. #    include    <stdefs.h>
  11. #endif
  12. #include    <string.h>
  13. #include    "lh.h"
  14.  
  15. #ifdef    __HIGHC__
  16. #    pragma    On(Align_labels);
  17. #endif
  18.  
  19. char        flg_r, flg_p, flg_x, flg_m, flg_a, flg_c, flg_n, flg_t, flg_u,
  20.             flg_v, flg_w, flg_i, flg_h = 1, flg_o, flg_z;
  21.  
  22. /*******************************
  23.                 get options
  24. *******************************/
  25. int         getopt(char *p)
  26. {
  27.     static char flg[] = "rpxmacntuvwihoz";
  28.     static char *flgpos[] =
  29.     {&flg_r, &flg_p, &flg_x, &flg_m, &flg_a,
  30.      &flg_c, &flg_n, &flg_t, &flg_u, &flg_v,
  31.      &flg_w, &flg_i, &flg_h, &flg_o, &flg_z};
  32.     static char val[] = "0-1+2";
  33.  
  34.     int         i;
  35.     char        s;
  36.     char       *q;
  37.  
  38.     while ((s = tolower(*p)) != 0)
  39.     {
  40.         p++;
  41.         q = strchr(flg, s);     /* search switch */
  42.         if (q)
  43.         {
  44.             i = q - flg;
  45.             if (*p && (q = strchr(val, *p)) != NULL)
  46.             {
  47.                 *flgpos[i] = (q - val) / 2;
  48.                 p++;
  49.             } else if (s == 'v' && *p)
  50.             {
  51.                 if (flg_v == 0) /* process of '/vSTRING' */
  52.                     flg_v = 1;
  53.                 pager = p;
  54.                 p = "";
  55.             } else if (s == 'w' && *p)
  56.             {
  57.                 flg_w = 1;        /* process of '/wSTRING' */
  58.                 workdir = p;
  59.                 p = "";
  60.             } else
  61.             {
  62.                 /* flip-flop */
  63.                 *flgpos[i] = !*flgpos[i];
  64.             }
  65.         } else if (s == 'k')
  66.         {
  67.             keyword = p;
  68.             p = "";
  69.         } else
  70.         {
  71.             if (s == '?')
  72.                 usage();
  73.             return 1;
  74.         }
  75.     }
  76.     return 0;
  77. }
  78.